<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>试题管理</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <link href="/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --teacher-accent: #4361ee;
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 导航栏样式 */
        .navbar {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }

        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            padding: 2rem 0;
        }

        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
        }

        .page-title {
            font-weight: 700;
            margin: 0;
            position: relative;
            padding-left: 20px;
        }

        .page-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 8px;
            height: 80%;
            background-color: var(--teacher-accent);
            border-radius: 4px;
        }

        /* 功能卡片 */
        .card {
            border: none;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
            transition: var(--transition);
            margin-bottom: 1.5rem;
            overflow: hidden;
        }

        .card-header {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
            color: white;
            padding: 1.25rem 1.5rem;
            font-weight: 700;
            display: flex;
            align-items: center;
        }

        .card-header i {
            margin-right: 10px;
            font-size: 1.25rem;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
            border: none;
            padding: 0.5rem 1.5rem;
            font-weight: 600;
            border-radius: 8px;
            transition: var(--transition);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
        }

        .btn-sm {
            padding: 0.25rem 0.8rem;
            font-size: 0.875rem;
        }

        /* 表格样式 */
        .table-container {
            padding: 1.5rem;
        }

        .table {
            margin-bottom: 0;
            border-collapse: separate;
            border-spacing: 0;
        }

        .table thead th {
            background-color: #f8f9fa;
            font-weight: 600;
            padding: 1rem 1.25rem;
            border-top: none;
            border-bottom: 2px solid #e9ecef;
        }

        .table tbody td {
            padding: 1rem 1.25rem;
            vertical-align: middle;
            border-top: 1px solid #e9ecef;
        }

        .table tbody tr {
            transition: var(--transition);
        }

        .table tbody tr:hover {
            background-color: rgba(67, 97, 238, 0.05);
        }

        /* 选项列表样式 */
        .option-list {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .option-list li {
            padding: 2px 0;
        }

        /* 操作按钮组 */
        .btn-group-sm .btn {
            margin-right: 0.5rem;
            transition: var(--transition);
        }

        .btn-warning {
            background: linear-gradient(135deg, #ffc107, #e0a800);
            border: none;
            color: #fff;
        }

        .btn-warning:hover {
            box-shadow: 0 5px 15px rgba(255, 193, 7, 0.4);
            transform: translateY(-2px);
        }

        .btn-danger {
            background: linear-gradient(135deg, #dc3545, #bd2130);
            border: none;
        }

        .btn-danger:hover {
            box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
            transform: translateY(-2px);
        }

        /* 页脚样式 */
        .footer {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 2rem 0;
            margin-top: auto;
        }

        .teacher .footer {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
        }

        .footer-title {
            font-weight: 700;
            margin-bottom: 1rem;
            font-size: 1.25rem;
        }

        .footer-links {
            list-style: none;
            padding: 0;
        }

        .footer-links li {
            margin-bottom: 0.5rem;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: var(--transition);
        }

        .footer-links a:hover {
            color: white;
            text-decoration: underline;
        }

        .social-icons {
            display: flex;
            gap: 15px;
            margin-top: 1rem;
        }

        .social-icons a {
            color: white;
            font-size: 1.5rem;
            transition: var(--transition);
        }

        .social-icons a:hover {
            transform: translateY(-3px);
        }

        .copyright {
            text-align: center;
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .navbar-brand {
                font-size: 1.2rem;
            }
            
            .page-header {
                flex-direction: column;
                align-items: flex-start;
            }
            
            .page-header .btn {
                margin-top: 1rem;
                width: 100%;
            }
            
            .table thead {
                display: none;
            }
            
            .table, .table tbody, .table tr, .table td {
                display: block;
                width: 100%;
            }
            
            .table tr {
                margin-bottom: 1.5rem;
                border-radius: 8px;
                box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            }
            
            .table td {
                text-align: right;
                padding-left: 50%;
                position: relative;
                border-top: none;
            }
            
            .table td::before {
                content: attr(data-label);
                position: absolute;
                left: 1rem;
                width: calc(50% - 1rem);
                padding-right: 1rem;
                text-align: left;
                font-weight: 600;
            }
            
            .table td:first-child {
                background-color: #f8f9fa;
                font-weight: 600;
                border-top-left-radius: 8px;
                border-top-right-radius: 8px;
            }
            
            .table td:last-child {
                border-bottom-left-radius: 8px;
                border-bottom-right-radius: 8px;
            }
            
            .btn-group-sm {
                display: flex;
                flex-direction: column;
                gap: 0.5rem;
            }
            
            .btn-group-sm .btn {
                margin-right: 0;
                width: 100%;
            }
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <a class="navbar-brand" href="#">
            <i class="fas fa-chalkboard-teacher"></i>在线考试系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/exam/manage"><i class="fas fa-tasks"></i> 考试管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" href="/teacher/question/manage"><i class="fas fa-book"></i> 题库管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/score/analysis"><i class="fas fa-chart-bar"></i> 成绩分析</a>
                </li>
            </ul>

            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/profile">
                        <i class="fas fa-user-circle"></i> 个人信息
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/logout">
                        <i class="fas fa-sign-out-alt"></i> 退出登录
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主内容区域 -->
<div class="main-content">
    <div class="container">
        <div class="card">
            <div class="card-header">
                <i class="fas fa-book"></i> 试题管理
            </div>
            
            <div class="table-container">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h2 class="page-title">试题列表</h2>
                    <a href="/teacher/question/add" class="btn btn-primary">
                        <i class="fas fa-plus-circle"></i> 添加试题
                    </a>
                </div>
                
                <div th:each="entry : ${questionsByCourse}" class="card mb-4">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0" th:text="${entry.key.courseName}">课程名称</h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>题目类型</th>
                                        <th>题目内容</th>
                                        <th>选项</th>
                                        <th>答案</th>
                                        <th>分值</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr th:if="${entry.value.empty}">
                                        <td colspan="6" class="text-center">暂无试题</td>
                                    </tr>
                                    <tr th:each="question : ${entry.value}">
                                        <td th:text="${question.type}" data-label="题目类型"></td>
                                        <td th:text="${question.content}" data-label="题目内容"></td>
                                        <td data-label="选项">
                                            <div th:if="${question.type == 'choice' || question.type == 'multiple'}">
                                                <ul class="option-list">
                                                    <th:block th:with="options=${#strings.arraySplit(question.options, ',')}">
                                                        <li th:each="option, stat : ${options}">
                                                            <span th:text="${#strings.substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', stat.index, stat.index + 1) + '. ' + #strings.replace(#strings.replace(option, '[', ''), ']', '')}"></span>
                                                        </li>
                                                    </th:block>
                                                </ul>
                                            </div>
                                            <span th:unless="${question.type == 'choice' || question.type == 'multiple'}">-</span>
                                        </td>
                                        <td th:text="${question.answer}" data-label="答案"></td>
                                        <td th:text="${question.score}" data-label="分值"></td>
                                        <td data-label="操作">
                                            <div class="btn-group btn-group-sm">
                                                <a th:href="@{/teacher/question/edit/{id}(id=${question.questionId})}" class="btn btn-warning">
                                                    <i class="fas fa-edit"></i> 编辑
                                                </a>
                                                <button class="btn btn-danger" th:onclick="'deleteQuestion(' + ${question.questionId} + ')'">
                                                    <i class="fas fa-trash-alt"></i> 删除
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank"><i class="fab fa-github fa-2x"></i></a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>

<!-- Bootstrap JS -->
<script src="/js/bootstrap.bundle.min.js"></script>
<script src="/js/axios.min.js"></script>
<script>
    function deleteQuestion(id) {
        if (confirm('确定要删除这道试题吗？')) {
            axios.post('/teacher/question/delete/' + id)
                .then(response => {
                    if (response.data === 'success') {
                        alert('删除成功');
                        location.reload();
                    } else {
                        alert(response.data);
                    }
                })
                .catch(error => {
                    alert('删除失败：' + error.message);
                });
        }
    }
</script>
</body>
</html>